package dltec.demo;

public class Goods implements Comparable<Goods>{

	String name;
	double price;
	
	public Goods() {
		super();
	}

	public Goods(String name, double price) {
		super();
		this.name = name;
		this.price = price;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}
	

	@Override
	public String toString() {
		return "[name=" + name + ", price=" + price + "]";
	}

	@Override
	public int compareTo(Goods g) {
		
		//定义比较规则：价格由低到高排序
		if(this.price > g.price){
			return 1;
		}else if(this.price < g.price){
			
			return -1;
		}else{
			//使用字符串里面自带的 CompareTo方法，自然比较由小到大，取反"-"，由大到小。
			return - this.name.compareTo(g.name);
		}
		

	}
	
	


	
}
